

import java.io.DataInputStream;
import org.json.JSONObject;

public class WikipediaSearch {
	
	public WikipediaSearch(String text)throws Exception{
		framework obj=new framework();
		@SuppressWarnings("deprecation")
		String line= (new DataInputStream(obj.gsearch("http://en.wikipedia.org/w/api.php?format=json&action=query&prop=info&inprop=url&"
			    + "titles="+ text.replace(" ", "+"))).readLine());
		getWikilinks(line);
	}
	public void getWikilinks(String line) throws Exception
    {
		
 	    JSONObject json = new JSONObject(line);
		JSONObject gson=json.getJSONObject("query");
		
		String sample=gson.getString("pages")	;
		String number;
		number=sample.substring(2,20);
		System.out.println(number);
		int i=0;
		for(i=0;number.charAt(i)!='"';i++)
		{}
		String xy=number.substring(0,i);
		
		JSONObject kson=gson.getJSONObject("pages");
		JSONObject lson=kson.getJSONObject(xy);
		String url=lson.getString("fullurl");
		System.out.println(url);
		
    }
}

